<?php
/**
 * ReadView.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/06/25
 * Time: 14:23
 */
namespace app\console\command\auto_curd\tpl;

class ReadView
{
    static public function begin($table,$th,$td,$PRI_NAME)
    {
        $date = date('Y/m/d',time());
        $time = date('H:i',time());
        $tpl = <<<EOF

{extend name="common@bootstrap" /}
{block name="body_content"}
<div class="btn-group">
    <a href="{:url('create')}" class="btn btn-default">添加</a>
</div>
<table class="table" data-auto-date="$date" data-auto-time="$time">
  <caption>{$table['table_comment']}</caption>
  <thead>
    <tr>
        <th>#</th>
$th
        <th>操作</th>
    </tr>
  </thead>
  <tbody>
  {volist name="list" id="row"}
    <tr>
        <td><input type="checkbox" name="ids[]" value="{\$row['{$PRI_NAME}']}"></td>
$td
        <td><a href="{:url('update')}?id={\$row['{$PRI_NAME}']}">编辑</a> <a href="{:url('delete')}?id={\$row['{$PRI_NAME}']}">删除</a></td>
EOF;
        return $tpl;
    }

    static public function thead($column)
    {
        $tpl = <<<EOF

        <th>{$column['column_comment']}</th>

EOF;
        return $tpl;
    }

    static public function content($column)
    {
        $tpl = <<<EOF

        <td>{\$row['{$column['column_name']}']|default="{$column['column_default']}"}</td>

EOF;
        return $tpl;
    }

    static public function end()
    {
        $tpl = <<<EOF

    </tr>
  {/volist}
  </tbody>
</table>
<div class="text-center">
{\$pagination}
</div>
{/block}

EOF;
        return $tpl;
    }
}